<!-- 物料库存 -->
<template>
<view style="height: 100vh;">
 <layout index="/pages/wms/index" layoutTitle="物料库存">
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物料名称" prop="materialName">
        <el-input v-model="queryParams.materialName" placeholder="请输入物料名称" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="型号" prop="materialModel">
        <el-input v-model="queryParams.materialModel" placeholder="请输入物料型号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="规格" prop="materialSpecification">
        <el-input v-model="queryParams.materialSpecification" placeholder="请输入物料规格" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain @click="handleAdd" v-hasPermi="['material:materialInventory:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain :disabled="single" @click="handleUpdate" v-hasPermi="['material:materialInventory:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain :disabled="multiple" @click="handleDelete" v-hasPermi="['material:materialInventory:remove']">删除</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="materialInventoryList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center"/>
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="仓库" align="center" prop="warehouseId" width="200"/>
      <el-table-column label="物料编号" align="center" prop="materialCode" width="200"/>
      <el-table-column label="物料名称" align="center" prop="materialName" width="200"/>
      <el-table-column label="物料型号" align="center" prop="materialModel" width="200"/>
      <el-table-column label="物料规格" align="center" prop="materialSpecification" width="200"/>
      <el-table-column label="物料单位" align="center" prop="materialUnit" width="200"/>
      <el-table-column label="物料单价" align="center" prop="materialPrice" width="200"/>
      <el-table-column label="总库存" align="center" prop="totalInventory" width="200"/>
      <el-table-column label="锁定库存" align="center" prop="freezeInventory" width="200"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template #default="scope">
          <el-button type="text" @click="handleMove(scope.row)" v-hasPermi="['material:materialInventory:edit']">移库</el-button>
          <el-button type="text" @click="handleUpdate(scope.row)" v-hasPermi="['material:materialInventory:edit']">修改</el-button>
          <el-button type="text" @click="handleDelete(scope.row)" v-hasPermi="['material:materialInventory:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"/>
  </div>
  </layout>
 </view>
</template>

<script>
export default {
  name: "MaterialInventory",
  data() {
    return {
      loading: true,
      ids: [],
      single: true,
      multiple: true,
      showSearch: true,
      total: 0,
      materialInventoryList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        materialName: null,
        materialModel: null,
        materialSpecification: null
      }
    };
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1;
      // 模拟数据
      this.materialInventoryList = [
        {
          id: 1,
          warehouseId: 101,
          materialCode: 'MC001',
          materialName: '物料A',
          materialModel: '型号A',
          materialSpecification: '规格A',
          materialUnit: '个',
          materialPrice: 100,
          totalInventory: 1000,
          freezeInventory: 100
        },
        {
          id: 2,
          warehouseId: 102,
          materialCode: 'MC002',
          materialName: '物料B',
          materialModel: '型号B',
          materialSpecification: '规格B',
          materialUnit: '个',
          materialPrice: 200,
          totalInventory: 2000,
          freezeInventory: 200
        }
      ];
      this.total = 2;
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        materialName: null,
        materialModel: null,
        materialSpecification: null
      };
      this.handleQuery();
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    handleAdd() {
      alert('新增功能暂未实现');
    },
    handleUpdate(row) {
      alert('修改功能暂未实现');
    },
    handleDelete(row) {
      alert('删除功能暂未实现');
    },
    handleMove(row) {
      alert('移库功能暂未实现');
    }
  }
};
</script>

<style scoped>
/* 整体容器 */
.container {
  min-height: 100vh;
  padding: 20rpx;
  background: linear-gradient(165deg, #f6fbf8, #e8f5f0);
}

/* 顶部统计卡片区域 */
.statistics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300rpx, 1fr));
  gap: 20rpx;
  margin-bottom: 30rpx;
}

.stat-card {
  background: linear-gradient(145deg, #ffffff, #f9fafb);
  border-radius: 16rpx;
  border: 1px solid rgba(39, 174, 96, 0.1);
  box-shadow: 0 8rpx 16rpx rgba(39, 174, 96, 0.1);
  padding: 24rpx;
  transition: all 0.3s ease;
  animation: fadeIn 0.5s ease forwards;
  opacity: 0;
}

.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }

.stat-card:hover {
  transform: translateY(-4rpx);
  box-shadow: 0 12rpx 24rpx rgba(39, 174, 96, 0.15);
}

.stat-title {
  font-size: 28rpx;
  color: #4a6572;
  margin-bottom: 12rpx;
  display: flex;
  align-items: center;
}

.stat-title .icon {
  margin-right: 10rpx;
  color: #27ae60;
  font-size: 32rpx;
}

.stat-value {
  font-size: 42rpx;
  font-weight: 700;
  color: #27ae60;
}

.stat-description {
  font-size: 24rpx;
  color: #7f8c8d;
  margin-top: 8rpx;
}

/* 搜索框样式 */
.search-area {
  background: #ffffff;
  border-radius: 16rpx;
  padding: 24rpx;
  box-shadow: 0 4rpx 12rpx rgba(39, 174, 96, 0.1);
  margin-bottom: 24rpx;
  animation: slideDown 0.5s ease forwards;
  opacity: 0;
  animation-delay: 0.4s;
}

.search-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 20rpx;
  align-items: center;
}

@media (max-width: 768px) {
  .search-form {
    grid-template-columns: 1fr;
  }
}

:deep(.el-input__inner) {
  border-radius: 8rpx !important;
  border-color: rgba(39, 174, 96, 0.2) !important;
}

:deep(.el-input__inner:focus) {
  border-color: #27ae60 !important;
  box-shadow: 0 0 0 2px rgba(39, 174, 96, 0.1) !important;
}

:deep(.el-button--primary) {
  background-color: #27ae60 !important;
  border-color: #27ae60 !important;
  box-shadow: 0 4rpx 8rpx rgba(39, 174, 96, 0.25);
  transition: all 0.3s ease;
}

:deep(.el-button--primary:hover) {
  background-color: #219654 !important;
  transform: translateY(-2rpx);
  box-shadow: 0 6rpx 12rpx rgba(39, 174, 96, 0.3);
}

/* 表格样式 */
.table-container {
  background: #ffffff;
  border-radius: 16rpx;
  padding: 20rpx;
  box-shadow: 0 4rpx 12rpx rgba(39, 174, 96, 0.1);
  animation: slideUp 0.5s ease forwards;
  opacity: 0;
  animation-delay: 0.5s;
}

:deep(.el-table) {
  border-radius: 10rpx;
  overflow: hidden;
}

:deep(.el-table__header) {
  background-color: rgba(39, 174, 96, 0.05) !important;
}

:deep(.el-table__header-wrapper th) {
  background-color: rgba(39, 174, 96, 0.05) !important;
  color: #2c3e50 !important;
  font-weight: 600 !important;
  padding: 20rpx 0 !important;
}

:deep(.el-table__body tr:hover > td) {
  background-color: rgba(39, 174, 96, 0.05) !important;
}

:deep(.el-table__row) {
  transition: all 0.3s ease;
}

/* 表格内按钮 */
:deep(.el-button--text) {
  color: #27ae60 !important;
}

:deep(.el-button--text:hover) {
  color: #219654 !important;
  background: rgba(39, 174, 96, 0.1) !important;
}

/* 分页控件 */
.pagination-container {
  margin-top: 24rpx;
  display: flex;
  justify-content: flex-end;
}

:deep(.el-pagination) {
  padding: 20rpx !important;
  border-radius: 8rpx;
  background-color: #f9fafb !important;
}

:deep(.el-pagination.is-background .el-pager li:not(.disabled).active) {
  background-color: #27ae60 !important;
  color: white !important;
}

/* 动画效果 */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20rpx); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20rpx); }
  to { opacity: 1; transform: translateY(0); }
}
</style>